package com.benchmark.springboot.controller;


import com.benchmark.springboot.model.User;
import com.benchmark.springboot.service.UserService;
import com.power.common.model.CommonResult;
import com.power.common.util.UUIDUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户操作接口
 *
 * @author yu
 * @date 2017-07-27 16:58:53
 */
@RestController
public class UserController {
    /**
     * 日志
     */
    private static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Resource
    private UserService userService;


    /**
     * 根据id用户信息
     *
     * @return
     */
    @GetMapping(value = "/query")
    public CommonResult<User> queryById() {
        User user = userService.queryById(0);
        return CommonResult.ok().setResult(user);
    }

    /**
     * 链路原样包返回
     *
     * @param traceId 链路id，一般为uuid
     * @return
     */
    @GetMapping(value = "/tracing/{traceId}")
    public CommonResult<String> traceId(@PathVariable String traceId) {
        return CommonResult.ok().setResult(traceId);
    }

    /**
     * 链路原样包返回
     *
     * @param traceId 链路id，一般为uuid
     * @param delay   延迟
     * @return
     */
    @GetMapping(value = "/tracing/{traceId}/{delay}",produces = "application/json")
    public CommonResult<String> traceIdDelay(@PathVariable String traceId, @PathVariable long delay)
            throws InterruptedException {
        Thread.sleep(delay);
        return CommonResult.ok().setResult(traceId);
    }


}